.PHONY: dep
dep:
	pipx install pre-commit

.PHONY: init
init:
	pre-commit install
	cargo deny fetch
	cargo b

.PHONY: test
test:
	@cargo nextest run --all-features --examples

.PHONY: release
release: test
	@cargo release tag --execute
	@git cliff -o CHANGELOG.md
	@git commit -a -n -m "Update CHANGELOG.md" || true
	@git push origin master
	@cargo release push --execute

.PHONY: update-submodule
update-submodule:
	@git submodule update --init --recursive --remote

examples/p2p_chat1:
	@export CHAT_P2P_PORT=9999 && export CHAT_P2P_PEER=/ip4/127.0.0.1/tcp/8888 && cargo run --example p2p_chat
examples/p2p_chat2:
	@export CHAT_P2P_PORT=8888 && export CHAT_P2P_PEER=/ip4/127.0.0.1/tcp/9999 && cargo run --example p2p_chat


examples/p2p_chat_with_mdns:
	@cargo run --example p2p_chat_with_mdns

examples/p2p_chat_with_dht:
	@echo "先启动一个节点"
	@export CHAT_P2P_MDNS_ENABLE=false && cargo run --example p2p_chat_with_dht
	@echo "启动第二个节点, 需要指定第一个节点的端口和 peer_id"
	@export CHAT_P2P_MDNS_ENABLE=false && export CHAT_P2P_BOOTSTRAP_PEERS=/ip4/127.0.0.1/tcp/{port}/p2p/{peer_id} && cargo run --example p2p_chat_with_dht

run-1:
	@RUST_LOG=DEBUG cargo run -- --base-path ./instance1 --grpc-port 9999 start

run-2:
	@RUST_LOG=DEBUG cargo run -- --base-path ./instance2 --grpc-port 9998 start

run-3:
	@RUST_LOG=DEBUG cargo run -- --base-path ./instance3 --grpc-port 9997 start

debugtest:
	@RUST_LOG=ERROR cargo test -- --nocapture
